package com.glsc.ngateway.common.base.converter.platform;

import com.alibaba.excel.util.CollectionUtils;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it.networkassets.dict.ItNetworkAssetsDictField;
import com.glsc.ngateway.common.api.platform.dto.it.networkassets.dict.ItNetworkAssetsDictFieldDto;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class ItNetworkAssetsDictFieldConverter {

    public static ItNetworkAssetsDictFieldDto do2Dto(ItNetworkAssetsDictField dictDo) {
        return Objects.isNull(dictDo) ? null : ItNetworkAssetsDictFieldDto.builder()
                .id(dictDo.getId())
                .code(dictDo.getCode())
                .desc(dictDo.getDescribtion())
                .type(dictDo.getType())
                .length(dictDo.getLength())
                .build();
    }

    public static List<ItNetworkAssetsDictFieldDto> do2Dto(List<ItNetworkAssetsDictField> dictDoList) {
        return CollectionUtils.isEmpty(dictDoList) ? java.util.Collections.EMPTY_LIST
                : dictDoList.stream().map(ItNetworkAssetsDictFieldConverter::do2Dto).collect(Collectors.toList());
    }

    public static ItNetworkAssetsDictField dto2Do(ItNetworkAssetsDictFieldDto dictDto) {
        return Objects.isNull(dictDto) ? null : ItNetworkAssetsDictField.builder()
                .id(dictDto.getId())
                .dictCode(dictDto.getDictCode())
                .describtion(dictDto.getDesc())
                .code(dictDto.getCode())
                .type(dictDto.getType())
                .length(dictDto.getLength())
                //转Do对象一般用于写入数据库，此联级属性先不做转换
//                .valueList(Collections.isEmpty(dictDto.getValueList()) ? java.util.Collections.EMPTY_LIST : dictDto.getValueList().stream().map(ItNetworkAssetsDictFieldValueConverter::dto2Do).collect(Collectors.toList()))
                .build();
    }

    public static List<ItNetworkAssetsDictField> dto2Do(List<ItNetworkAssetsDictFieldDto> dictDtoList) {
        return CollectionUtils.isEmpty(dictDtoList) ? java.util.Collections.EMPTY_LIST
                : dictDtoList.stream().map(ItNetworkAssetsDictFieldConverter::dto2Do).collect(Collectors.toList());
    }
}
